#!/usr/bin/env python
#-*-coding:utf-8-*-
# ---------------------------------
# version:  1.0
#
# create-time:      <2008/12/12 08:54:12>
# last-update-time: <halida 12/19/2008 16:41:45>
# ---------------------------------
# module : reminder

from qtlib import *

import entity

CHECK_INTERNAL_TIME = 10

class Reminder():
    """check entity pool if there are entities on schedule."""
    def __init__(self,pool):
        self.pool = pool
        self.timer = QTimer()
        conn(self.timer,"timeout()",self.process)
    
    def run(self):
        self.timer.start(1000*CHECK_INTERNAL_TIME)

    def process(self):
        logging.info("reminder checking..")
        now = datetime.now()
        changed = False
        
        for e in self.pool.get():
            #check schedule
            if e.checkScheduled(now):
                changed = True
            #check loop
            if e.looped:
                if e.checkLoop(now):
                    changed = True
        #change flag
        if changed:
            self.pool.changed()
        
